﻿using System;
using YEA.Infrastructure.Gateway;
using YEA.Utilities.Notifications.Converter;

namespace YEA.Utilities.Notifications
{
    internal class Client : IDisposable
    {
        protected GatewayFactory gf;
        protected string _publisherName;
        internal Client( string publisherName)
        {
            _publisherName = publisherName;
            gf = new GatewayFactory();
        }
        ~Client()
        {
            Dispose(false);
        }
        internal void Send( Notification message)
        {
            var mc = new NotificationConverter();
            var publisher = gf.GetPublisher(_publisherName, mc.ConvertObjectToMessage);
            publisher.Publish(message);
        }


        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }
        internal void Dispose(bool disposing)
        {
            if (disposing)
            {
                gf.Dispose();
            }
            gf = null;
            _publisherName = null;
        }
    }


}
